package top.glkj.hms.controller.room;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.glkj.hms.entity.Room;
import top.glkj.hms.entity.RoomType;
import top.glkj.hms.service.RoomService;
import top.glkj.hms.utils.Result;

import javax.annotation.security.PermitAll;

/**
 * @author : xgl
 * @version : 0.0.1
 * @date :2020/12/7 23:31
 */
@Api(tags = "客房管理")
@RestController
@RequestMapping("/room/management")
public class RoomManagementController {
    private final RoomService roomService;
    @Autowired
    public RoomManagementController(RoomService roomService) {
        this.roomService = roomService;
    }

    /**
     * 添加房间
     *
     * @param room
     */
    @ApiOperation("添加客房")
    @PostMapping
    public Result addRoom(Room room) {
        return roomService.addRoom(room);
    }

    @ApiOperation("修改客房")
    @PutMapping
    public Result updateRoom(Room room) {
        return roomService.updateRoom(room);
    }

    @ApiOperation("查询客房")
    @GetMapping
    public Result getRoom() {
        return roomService.getAll();
    }

    @ApiOperation("删除客房")
    @DeleteMapping
    public Result removeRoom(Room room) {
        return roomService.remove(room);
    }

    @ApiOperation("彻底删除客房")
    @DeleteMapping("/delete")
    public Result deleteRoom(Room room) {
        return roomService.delete(room);
    }

    @ApiOperation("添加客房类型")
    @PostMapping("/roomType")
    public Result addRoomType(RoomType roomType){
        return roomService.addRoomType(roomType);
    }

    @ApiOperation("获取客房类型")
    @GetMapping("/roomType")
    public Result getRoomType(){
        return roomService.getRoomType();
    }

    @ApiOperation("修改客房类型")
    @PutMapping("/roomType")
    public Result updateRoomType(RoomType roomType){
        return roomService.updateRoomType(roomType);
    }

    @ApiOperation("删除客房类型")
    @DeleteMapping("/roomType/delete/{id}")
    public Result deleteRoomType(@PathVariable("id") Long id){
        return roomService.deleteRoomType(id);
    }

    @ApiOperation("移除客房类型")
    @DeleteMapping("/roomType/{id}")
    public Result removeRoomType(@PathVariable("id") Long id){
        return roomService.removeRoomType(id);
    }

    @ApiOperation("分页查询客房类型")
    @GetMapping("/roomType/{size}/{page}")
    public Result getRoomTypeByPageAndSize(@PathVariable("page") int page,@PathVariable("size") int size) {
        return roomService.getRoomTypeByPageAndSize(page,size);
    }
    @ApiOperation("分页查询客房")
    @GetMapping("/{size}/{page}")
    public Result getRoomByPageAndSize(@PathVariable("page") int page,@PathVariable("size") int size) {
        return roomService.getRoomByPageAndSize(page,size);
    }

    @PermitAll
    @ApiOperation("根据创建时间排序获取房间")
    @GetMapping("/indexByTime")
    public Result getRoomByCreateTime(){return roomService.getRoomByCreateTime();}

    @PermitAll
    @ApiOperation("根据房间类型获取房间")
    @GetMapping("/indexByType")
    public Result getRoomByType(){return roomService.getRoomByType();}

    @PermitAll
    @ApiOperation("根据房间评分获取房间")
    @GetMapping("/indexByScore")
    public Result getRoomByScore(){return roomService.getRoomByScore();}
}
